package com.soujiayi.activity;

import java.util.ArrayList;
import java.util.HashMap;

import android.app.ListActivity;
import android.app.SearchManager;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ListView;
import android.widget.SimpleAdapter;

public class GoodsListActivity extends ListActivity {

	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		((MyApplication) this.getApplication()).addActivity(this);
		setContentView(R.layout.goodslist);
		handleIntent(getIntent());
	}

	public void onNewIntent(Intent intent) {
		setIntent(intent);
		handleIntent(intent);
	}

	public void onListItemClick(ListView l, View v, int position, long id) {
		// ��ÿ���������ʱ�Ĵ������
		 super.onListItemClick(l, v, position, id);
		  System.out.println("id is:" + id);
		  System.out.println("position is:" + position);
	}

	private void handleIntent(Intent intent) {
		if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
			String query = intent.getStringExtra(SearchManager.QUERY);
			doSearch(query);
		}
	}

	private void doSearch(String queryStr) {
		// ִ������Ĳ�ѯ����� ��
		 ArrayList<HashMap<String, String>> list = new ArrayList<HashMap<String, String>>();// ʵ��ArrayList���?�������HashMap����
		  // ʵ��HashMap������������û����IP
		  HashMap<String, String> map1 = new HashMap<String, String>();
		  map1.put("index", "1");
		  map1.put("result", queryStr+"__1");
		  HashMap<String, String> map2 = new HashMap<String, String>();
		  map2.put("index", "2");
		  map2.put("result", queryStr+"__2");
		  HashMap<String, String> map3 = new HashMap<String, String>();
		  map3.put("index", "3");
		  map3.put("result", queryStr+"__3");
		  // ���HashMap���ϵ�ArrayList������
		  
		
		  list.add(map1);
		  list.add(map2);
		  list.add(map3);
		  SimpleAdapter listSimpleAdapter = new SimpleAdapter(this, list,
		    R.layout.goodslistitem, new String[] { "index", "result" },
		    new int[] { R.id.tv_goodslistitem_index, R.id.tv_goodslistitem_result });// ʵ��������
		  this.setListAdapter(listSimpleAdapter);
		 }
		 // �����ListView����ʱ�������¼�
		
}